import React, {Component} from 'react';
const TodoActions = require('../../actions/TodoActions');

class TodoListAdd extends Component {

  constructor(props) {
    super(props);
    this._inputChange = this._inputChange.bind(this);
    this._add = this._add.bind(this);
    this.state = {
      value: ''
    };
  }

  static propTypes = {

  }

  static defaultProps = {

  }


  _add() {

    if (this.state.value != '') {

      TodoActions._create(this.state.value);
      this.setState({value: ''});
    } else {
      alert('请输入内容');
    }
  }

  _inputChange(event) {
    this.setState({value: event.target.value});
  }

  render() {

    return (
      <div>
        <input
          onChange={this._inputChange}
          value = this.state.value
           />
        <button onClick={this._add}>add</button>
      </div>
    );
  }
}


export default TodoListAdd;

